//
//  FeaturedBookCell.m
//  ZYTS-iPhone
//
//  Created by yuzhou on 12-12-7.
//  Copyright (c) 2012年 wzyk. All rights reserved.
//

#import "FeaturedBookCell.h"
#import "UIImageView+WebCache.h"
#import <QuartzCore/QuartzCore.h>

@implementation FeaturedBookCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    coverImageView.layer.shadowColor = [UIColor blackColor].CGColor;
    coverImageView.layer.shadowOpacity = 0.45f;
    coverImageView.layer.shadowOffset = CGSizeMake(-6.0f, -3.0f);
    coverImageView.layer.masksToBounds = NO;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:coverImageView.frame];
    coverImageView.layer.shadowPath = path.CGPath;
}

- (void)updateDisplay
{
    if (self.bookInfo) {
        NSString *imageURL = [[self.bookInfo valueForKey:@"image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [coverImageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"default_image"] options:SDWebImageRetryFailed];
        titleLabel.text = [self.bookInfo valueForKey:@"item_name"];
        artistLabel.text = [self.bookInfo valueForKey:@"broadcaster"];
        chapterLabel.text = [NSString stringWithFormat:@"%@",[self.bookInfo valueForKey:@"sub_count"]];
        sharedLael.text = [NSString stringWithFormat:@"%@",[self.bookInfo valueForKey:@"comment_count"]];
        collectedLabel.text = [NSString stringWithFormat:@"%@",[self.bookInfo valueForKey:@"favorite_count"]];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    
    [UIView animateWithDuration:animated?0.5:0 animations:^{
        if (highlighted) {
            self.contentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
        }
        else {
            self.contentView.backgroundColor = [UIColor clearColor];
        }
    }];
}

- (void)dealloc {
    [coverImageView release];
    [titleLabel release];
    [artistLabel release];
    [chapterLabel release];
    [sharedLael release];
    [collectedLabel release];
    [_bookInfo release],_bookInfo = nil;
    [super dealloc];
}
@end
